{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "dstImg = np.zeros((height,width,1),np.uint8)\n",
    "# 算法：newPixel = grayCurrentPixel - grayNextPixel + 150\n",
    "for i in range(0,height):\n",
    "    # 因为j+1,所以循环上届减一避免越界\n",
    "    for j in range(0,width-1):\n",
    "        grayCurrentPixel = int(gray[i,j])\n",
    "        grayNextPixel = int(gray[i,j+1])\n",
    "        newPixel = grayCurrentPixel - grayNextPixel + 150\n",
    "        if newPixel > 255:\n",
    "            newPixel = 255\n",
    "        if newPixel < 0:\n",
    "            newPixel = 0\n",
    "        dstImg[i,j] = newPixel\n",
    "cv2.imshow('dstImg',dstImg)\n",
    "cv2.waitKey(0)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
